﻿namespace AzManAPI.AzManClient.Converters
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Data;
    using System.Windows;

    public class BoolToVisibilityConverter : IValueConverter
    {
        public virtual object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if ((targetType == typeof(Visibility)) && ((value != null) || (value.GetType() == typeof(bool))))
            {
                bool val = (bool)value;

                if (val)
                {
                    return Visibility.Visible;
                }

                return Visibility.Hidden;
            }

            throw new InvalidCastException();
        }

        public virtual object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if ((targetType == typeof(bool)) && ((value != null) || (value.GetType() == typeof(Visibility))))
            {
                Visibility val = (Visibility)value;

                return val == Visibility.Visible;
            }

            if (value == null)
            {
                return false;
            }

            throw new InvalidCastException();
        }
    }
}